package com.qf.controller;

import com.qf.entity.Grade;
import com.qf.entity.Users;
import com.qf.service.UsersService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * 2019/10/9
 * Administrator
 * springboot1009
 * 面向对象面向君  不负代码不负卿
 */
@RestController  //等价于@ResponseBody+@Controller
public class TestController {
   /* @RequestMapping("/test")
    public String test1(){
        System.out.println("test1----");
        return "success";
    }


    @RequestMapping("/test2")
    public Users test2(){
        Users users = new Users(1, "张三", new Date());
        Grade grade=new Grade(1,"一年级");
        users.setGrade(grade);
        return users;
    }*/

    @Resource
    private UsersService usersService;

    @RequestMapping("/getuserlist")
    public List<Users> test3(){
        List<Users> usersList = usersService.getall();
        return usersList;
    }

    //新增用户信息   http://localhost:8080/insertuser?username=abc
    @RequestMapping("/insertuser")
    public String test4(Users users){
        users.setBirthday(new Date());
        Users insert = usersService.insert(users);
        if(insert!=null){
            return "success";
        }
        return "error";
    }
}
